<template>
	<view>
		<view class="title">
			<view class="title-text">
				<text v-if="current == 0">应收</text>
				<text v-else>应还</text>
			</view>
			<view class="title-money">
				<u-icon name="rmb" size="40" color="#303133"></u-icon>
				<text>{{money}}</text>
			</view>
		</view>
		
		<view>
			<u-divider lineColor="#82848a" :dot="true"></u-divider>
		</view>
		
		<view class="checkbox">
			<u-subsection 
				:list="dividerList" 
				:current="current" 
				mode="subsection"
				activeColor="#007AFF"
				@change="sectionChange"
				fontSize="17"
				></u-subsection>
		</view>
		<view class="divider">
			<u-divider lineColor="#82848a"></u-divider>
		</view>
		
		<view class="cell-group" v-for="(item1, index1) in list" :key="index1">
			<view class="cell-icon">
				<u-icon name="/static/account/info/borrow.png" size="28" color="#2979ff" ></u-icon>
			</view>
			<view class="cell-item" @click="getRepayment(index1)">
				<view class="cell-info">
					<view class="info-text">
						<text>{{item1.person}}&nbsp;&nbsp;{{item1.borrowDate}}</text>
					</view>
					<view class="info-remarks">
						<text v-if="item1.state == 1">已收{{item1.refundMoney}}</text>
						<text v-else>已还{{item1.refundMoney}}</text>
					</view>
				</view>
				<view class="cell-money">
					<text>{{[item1.state == 1 ? '-' : '+']+item1.borrowMoney}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				title_text: "",
				money: 0,
				state: 1,
				billDate: "",
				billType: "",
				dividerList: [{"value": 0,"name": "借出"	},{"value": 1,"name": "借入"}],
				list: []
			}
		},
		onShow() {
			
		},
		onLoad(options) {
			let data = JSON.parse(options.data)
			this.current = data.borrowState
			this.getBorrowBill()
		},
		methods: {
			sectionChange(index){
				this.current = index;
				this.getBorrowBill()
			},
			getRepayment (num) {
				let data = this.list[num]
				console.log(this.list)
				console.log(data)
				uni.navigateTo({
					url: '/pages/account/repayment?data='+JSON.stringify(data)
				})
			},
			getBorrowBill () {
				let params = {
					"userId": uni.getStorageSync('userId'),
					"state": this.current^1
				}
				const _this = this
				uni.request({
					header: {
						  'Content-Type': 'application/x-www-form-urlencoded',
						  'token': uni.getStorageSync('token') 
					   }, 
					url: this.$USER_AVATOR_URL.USER_AVATOR_URL+"/borrow/loadborrowbill",
					method: 'POST',
					data: params,
					success(res) {
						_this.list = res.data.data.list
						_this.money = res.data.data.borrowMoney
					}
				})
			}
		},


	}
</script>

<style>
	
	.title {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 60rpx;
	}
	.title-text {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 35rpx;
		color: #82848a;
	}
	.title-money {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 80rpx;
		font-weight: bolder;
		margin-top: 15rpx;
	}
	
	.checkbox{
		margin-left: 150rpx;
		margin-right: 150rpx;
	}
	.divider{
		margin-top: 30rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-bottom: 40rpx;
	}
	
	.cell-group {
		display: flex;
		flex-wrap: wrap;
		margin-top: 25rpx;
		margin-left: 30rpx;
		margin-right: 20rpx;
	}
	.cell-icon {
		width: 85rpx;
		height: 85rpx;
		display: flex;
		align-items: center;
		background-color: #2979ff;
		
		border-radius: 100%;
		box-sizing: border-box;
		justify-content: center;
		align-items: center;
	}
	.cell-item {
		height: 100rpx;
		display: flex;
		flex-wrap: wrap;
		border-bottom: #c8c9cc;
		border-style: hidden hidden solid hidden;
		border-width: 1rpx;
	}
	.cell-info {
		width: 380rpx;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		margin-left: 20rpx;
	}
	.info-text {
		font-size: 35rpx;
		width: 400rpx;
		height: 60rpx;
	}
	.info-remarks {
		width: 400rpx;
		color: #909399;
	}
	.cell-money {
		width: 200rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		
		font-size: 40rpx;
		font-weight: bolder;
	}
</style>
